export default function (module, __webpack_exports__, __webpack_require__) {

    "use strict";
    __webpack_require__.d(__webpack_exports__, "a", function () { return addBillboard; });
    __webpack_require__.d(__webpack_exports__, "c", function () { return addPoint; });
    __webpack_require__.d(__webpack_exports__, "d", function () { return getCityByxzqhdm; });
    __webpack_require__.d(__webpack_exports__, "h", function () { return watchSingleClick; });
    __webpack_require__.d(__webpack_exports__, "g", function () { return watchDoubleClick; });
    __webpack_require__.d(__webpack_exports__, "f", function () { return watchCamera; });
    __webpack_require__.d(__webpack_exports__, "e", function () { return getFlyLineData; });
    __webpack_require__.d(__webpack_exports__, "b", function () { return addLine; });
    var core_js_modules_es_array_filter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("4de4");
    var core_js_modules_es_array_filter__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(core_js_modules_es_array_filter__WEBPACK_IMPORTED_MODULE_0__);
    var core_js_modules_es_array_for_each__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("4160");
    var core_js_modules_es_array_for_each__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(core_js_modules_es_array_for_each__WEBPACK_IMPORTED_MODULE_1__);
    var core_js_modules_es_array_slice__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fb6a");
    var core_js_modules_es_array_slice__WEBPACK_IMPORTED_MODULE_2___default = __webpack_require__.n(core_js_modules_es_array_slice__WEBPACK_IMPORTED_MODULE_2__);
    var core_js_modules_es_function_name__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("b0c0");
    var core_js_modules_es_function_name__WEBPACK_IMPORTED_MODULE_3___default = __webpack_require__.n(core_js_modules_es_function_name__WEBPACK_IMPORTED_MODULE_3__);
    var core_js_modules_es_object_assign__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("cca6");
    var core_js_modules_es_object_assign__WEBPACK_IMPORTED_MODULE_4___default = __webpack_require__.n(core_js_modules_es_object_assign__WEBPACK_IMPORTED_MODULE_4__);
    var core_js_modules_es_object_to_string__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("d3b7");
    var core_js_modules_es_object_to_string__WEBPACK_IMPORTED_MODULE_5___default = __webpack_require__.n(core_js_modules_es_object_to_string__WEBPACK_IMPORTED_MODULE_5__);
    var core_js_modules_es_regexp_to_string__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("25f0");
    var core_js_modules_es_regexp_to_string__WEBPACK_IMPORTED_MODULE_6___default = __webpack_require__.n(core_js_modules_es_regexp_to_string__WEBPACK_IMPORTED_MODULE_6__);
    var core_js_modules_web_dom_collections_for_each__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("159b");
    var core_js_modules_web_dom_collections_for_each__WEBPACK_IMPORTED_MODULE_7___default = __webpack_require__.n(core_js_modules_web_dom_collections_for_each__WEBPACK_IMPORTED_MODULE_7__);
    var E_Project_wallmap_node_modules_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("2909");
    var _geo_json__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("e0c3");
    var _geo_json__WEBPACK_IMPORTED_MODULE_9___namespace = __webpack_require__.t("e0c3", 1);

    /**
     * 私有api（底层api），不对外暴露
     * viewer 代表 window.viewer , 所以只能在viewer挂在完后使用
     */

    /**
     * 打点billboard私有方法
     * @param {Number} lon 经度 必填
     * @param {Number} lat 纬度 必填
     * @param {String} imgUrl 图片路径 必填
     * @param {String} name 名称 可选
     * @param {Number} width 用于指定图片的宽度（以像素为单位），并覆盖原始尺寸 可选
     * @param {Number} height 用于指定图片的高度（以像素为单位），并覆盖原始尺寸 可选
     * @param {Number| Property} scale 图片缩放比例 可选
     * @param {Boolean} click 是否可点击 可选
     * @param {Number} doubleClickHeight 双击高度 可选
     * @param {Object} attribute 点属性 可选
     * @param {String} popContent 单击弹框内容 可选
     * @param {String} pointHeight 点的高度 可选
     * @param {String} doubleClickPitch 双击pitch 可选
     * @return entity
     */
    function addBillboard(lon, lat, imgUrl, _ref) {
        var _ref$name = _ref.name,
            name = _ref$name === void 0 ? 'Point' : _ref$name,
            width = _ref.width,
            height = _ref.height,
            scale = _ref.scale,
            _ref$click = _ref.click,
            click = _ref$click === void 0 ? true : _ref$click,
            _ref$shengClick = _ref.shengClick,
            shengClick = _ref$shengClick === void 0 ? false : _ref$shengClick,
            _ref$doubleClickHeigh = _ref.doubleClickHeight,
            doubleClickHeight = _ref$doubleClickHeigh === void 0 ? 5000 : _ref$doubleClickHeigh,
            _ref$attribute = _ref.attribute,
            attribute = _ref$attribute === void 0 ? {} : _ref$attribute,
            popContent = _ref.popContent,
            pointHeight = _ref.pointHeight,
            _ref$doubleClickPitch = _ref.doubleClickPitch,
            doubleClickPitch = _ref$doubleClickPitch === void 0 ? -90 : _ref$doubleClickPitch;
        var h = pointHeight ? pointHeight : 0;
        var entity = viewer.entities.add({
            name: name,
            position: Cesium.Cartesian3.fromDegrees(lon, lat, h),
            billboard: {
                image: imgUrl,
                width: width,
                height: height,
                scale: scale,
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                HorizontalOrigin: Cesium.HorizontalOrigin.CENTER
            },
            attribute: attribute,
            click: click,
            shengClick: shengClick,
            doubleClickHeight: doubleClickHeight,
            lon: lon,
            lat: lat,
            popContent: popContent,
            doubleClickPitch: doubleClickPitch
        });
        return entity;
    }

    /**
     * 添加圆点
     * @param {Number} lon 经度
     * @param {Number} lat 纬度
     * @param {Array} color 颜色
     * @param {Array} outlineColor 指定轮廓的颜色
     * @param {Number} outlineWidth 一个数字属性，用于指定轮廓宽度（以像素为单位）
     * @param {String} name 名称
     * @param {Number} pixelSize 大小
     * @param {Boolean} click 是否可点击
     * @param {Number|Rectangle} doubleClickHeight 双击高度
     * @param {Object} attribute 属性
     * @param {String} popContent 单击弹框内容
     * @return entity
     */
    function addPoint(lon, lat, _ref2) {
        var _ref2$color = _ref2.color,
            color = _ref2$color === void 0 ? [255, 0, 0, 255] : _ref2$color,
            outlineColor = _ref2.outlineColor,
            outlineWidth = _ref2.outlineWidth,
            _ref2$name = _ref2.name,
            name = _ref2$name === void 0 ? "Point" : _ref2$name,
            pixelSize = _ref2.pixelSize,
            _ref2$click = _ref2.click,
            click = _ref2$click === void 0 ? true : _ref2$click,
            _ref2$doubleClickHeig = _ref2.doubleClickHeight,
            doubleClickHeight = _ref2$doubleClickHeig === void 0 ? 5000 : _ref2$doubleClickHeig,
            _ref2$attribute = _ref2.attribute,
            attribute = _ref2$attribute === void 0 ? {} : _ref2$attribute,
            popContent = _ref2.popContent;
        var Cesiumcolor;

        if (Object.prototype.toString.apply(color) === '[object Array]') {
            var _Cesium$Color;

            Cesiumcolor = (_Cesium$Color = Cesium.Color).fromBytes.apply(_Cesium$Color, Object(E_Project_wallmap_node_modules_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_8__[/* default */ "a"])(color));
        } else {
            Cesiumcolor = color;
        }

        var entity = viewer.entities.add({
            name: name,
            position: Cesium.Cartesian3.fromDegrees(lon, lat),
            point: {
                show: true,
                color: Cesiumcolor,
                outlineColor: outlineColor,
                outlineWidth: outlineWidth,
                pixelSize: pixelSize
            },
            // 添加其他属性
            attribute: attribute,
            click: click,
            doubleClickHeight: doubleClickHeight,
            lon: lon,
            lat: lat,
            popContent: popContent
        });
        return entity;
    }

    /**
     * 根据行政区划代码获取城市
     * @param {Number} xzqhdm 行政区划代码 
     */
    function getCityByxzqhdm(xzqhdm) {
        var city = _geo_json__WEBPACK_IMPORTED_MODULE_9__.filter(function (v) {
            return v.xzqhDm === xzqhdm;
        });

        if (!city.length) {
            throw new Error("".concat(xzqhdm, " could not be found in geoData"));
        } else {
            return city[0];
        }
    }

    // 单击执行定时器
    var clickTimer = null;

    /**
     * 单击监听
     * @param {Function} callback 单机执行的方法 
     */
    function watchSingleClick(callback) {
        // 创建并获取一个监听器
        var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
        handler.setInputAction(function (click) {
            clearTimeout(clickTimer); // 获取点击的要素

            var pick = viewer.scene.pick(click.position);

            if (pick && pick.id && pick.id.click) {
                var entity = pick.id;
                clickTimer = setTimeout(function () {
                    viewer.pop.show(entity.lon, entity.lat, entity.popContent, entity); // 返回属性时 添加一个字段 判断双击单击

                    var attribute = Object.assign({}, entity.attribute, {
                        type: 'SingleClick'
                    });
                    callback(attribute);
                }, 500);
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    }

    /**
     * 双击监听
     * @param {Function} callback 单机执行的方法 
     */
    function watchDoubleClick(callback, wallmap) {
        // 创建并获取一个监听器
        var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
        handler.setInputAction(function (click) {
            // 清除单击timer
            clearTimeout(clickTimer); // 获取点击的要素

            var pick = viewer.scene.pick(click.position);
            var isCallback = false;

            if (pick && pick.id && (pick.id.click || pick.id.shengClick)) {
                var entity = pick.id; // 返回属性时 添加一个字段 判断双击单击

                var attribute = Object.assign({}, entity.attribute, {
                    type: 'DoubleClick'
                });

                if (Object.prototype.toString.apply(entity.doubleClickHeight) === '[object Number]') {
                    // 如果双击高度是一个数字，根据坐标进行定位。
                    wallmap.locationByLonLat(entity.lon, entity.lat, {
                        pitch: entity.doubleClickPitch,
                        range: entity.doubleClickHeight
                    });
                } else {
                    // 如果双击高度是不是一个数字。进行四至定位。
                    var option = {
                        pitch: entity.doubleClickPitch
                    };
                    var p = wallmap.locationfourByxzqhdm(entity.doubleClickHeight, option); // 如果配置了省份双击，emit当前四至。

                    if (pick.id.shengClick) {
                        isCallback = true;
                        callback(attribute, p);
                    }
                }

                if (!isCallback) {
                    callback(attribute);
                }
            }
        }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
    }

    /**
     * 相机监听
     */
    function watchCamera() {
        var callbackFun = Array.prototype.slice.apply(arguments);
        viewer.scene.camera.moveEnd.addEventListener(function () {
            callbackFun.forEach(function (v) {
                v();
            });
        });
    }

    /**
     * 生成飞线数据
     * @param {Object} start 起点 {lon, lat}
     * @param {Object} end 终点 {lon, lat}
     * @param {Number} height 高度 可选
     */
    function getFlyLineData(start, end) {
        var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 50000;
        var e = {
            x1: start.lon,
            y1: start.lat,
            x2: end.lon,
            y2: end.lat
        };
        return getFlyLine(e);

        function getFlyLine(e) {
            var cartesians = getBSRxyz(e.x1, e.y1, e.x2, e.y2, height);
            return cartesians;
        }

        function getBSRxyz(x1, y1, x2, y2, h) {
            var arr3d = getBSRPoints(x1, y1, x2, y2, h);
            var arrAll = [];

            for (var i in arr3d) {
                arrAll.push([Cesium.Math.toRadians(arr3d[i][0]), Cesium.Math.toRadians(arr3d[i][1]), arr3d[i][2]]);
            }

            return arrAll;
        }

        function getBSRPoints(x1, y1, x2, y2, h) {
            var point1 = [y1, 0];
            var point2 = [(y2 + y1) / 2, h];
            var point3 = [y2, 0];
            var arr = getBSR(point1, point2, point3);
            var arr3d = [];

            for (var i in arr) {
                var x = (x2 - x1) * (arr[i][0] - y1) / (y2 - y1) + x1;
                arr3d.push([x, arr[i][0], arr[i][1]]);
            }

            return arr3d;
        } // 生成贝塞尔曲线


        function getBSR(point1, point2, point3) {
            var ps = [{
                x: point1[0],
                y: point1[1]
            }, {
                x: point2[0],
                y: point2[1]
            }, {
                x: point3[0],
                y: point3[1]
            }];
            var guijipoints = CreateBezierPoints(ps, 100);
            return guijipoints;
        } // 贝赛尔曲线算法
        // 参数：
        // anchorpoints: [{ x: 116.30, y: 39.60 }, { x: 37.50, y: 40.25 }, { x: 39.51, y: 36.25 }]


        function CreateBezierPoints(anchorpoints, pointsAmount) {
            var points = [];

            for (var i = 0; i < pointsAmount; i++) {
                var point = MultiPointBezier(anchorpoints, i / pointsAmount);
                points.push([point.x, point.y]);
            }

            return points;
        }

        function MultiPointBezier(points, t) {
            var len = points.length;
            var x = 0,
                y = 0;

            var erxiangshi = function erxiangshi(start, end) {
                var cs = 1,
                    bcs = 1;

                while (end > 0) {
                    cs *= start;
                    bcs *= end;
                    start--;
                    end--;
                }

                return cs / bcs;
            };

            for (var i = 0; i < len; i++) {
                var point = points[i];
                x += point.x * Math.pow(1 - t, len - 1 - i) * Math.pow(t, i) * erxiangshi(len - 1, i);
                y += point.y * Math.pow(1 - t, len - 1 - i) * Math.pow(t, i) * erxiangshi(len - 1, i);
            }

            return {
                x: x,
                y: y
            };
        }
    }

    /**
     * 添加飞线
     * @param {*} positions 设置指定 Cartesian3 数组的属性定义线条的位置
     * @param {MaterialProperty} material 获取或设置指定用于绘制折线的材料的属性
     * @param {String} name 名称
     * @param {Number} width 宽度
     */
    function addLine(positions, material, _ref3) {
        var _ref3$name = _ref3.name,
            name = _ref3$name === void 0 ? 'Line' : _ref3$name,
            _ref3$width = _ref3.width,
            width = _ref3$width === void 0 ? 3 : _ref3$width;
        var entity = viewer.entities.add({
            name: name,
            polyline: {
                positions: positions,
                width: width,
                material: material
            }
        });
        return entity;
    }
}